home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 343_01 / cips2.c < prev    next >
C/C++ Source or Header  |  1991-05-22  |  18KB  |  665 lines

  1.  
  2.         /*****************************************************
  3.         *
  4.         *       file d:\cips\rstring.c
  5.         *
  6.         *       Functions: This file contains
  7.         *            read_string
  8.         *            clear_buffer
  9.         *            long_clear_buffer
  10.         *
  11.         *       Purpose: This function reads a string of input
  12.         *            from the keyboard.
  13.         *
  14.         *******************************************************/
  15.  
  16. #include "d:\cips\cips.h"
  17.  
  18.  
  19. read_string(string)
  20.         char *string;
  21. {
  22.         int     eof,
  23.                 letter,
  24.                 no_error;
  25.  
  26.         eof = -1;
  27.         no_error = 0;
  28.  
  29.         while((letter = getchar()) != '\n' &&
  30.                letter !=  eof)
  31.            *string++ = letter;
  32.  
  33.         *string = '\0';
  34.  
  35.         return((letter == eof) ? eof : no_error);
  36.  
  37. }       /* ends read_string */
  38.  
  39.  
  40.  
  41. clear_buffer(string)
  42.    char string[];
  43. {
  44.    int i;
  45.    for(i=0; i<MAX_NAME_LENGTH; i++)
  46.       string[i] = ' ';
  47. }
  48.  
  49.  
  50.  
  51. long_clear_buffer(string)
  52.    char string[];
  53. {
  54.    int i;
  55.    for(i=0; i<300; i++)
  56.       string[i] = ' ';
  57. }
  58.  
  59.  
  60.            /******************************************************
  61.            *
  62.            *       file d:\cips\mof.c
  63.            *
  64.            *       Functions: This file contains
  65.            *          my_open
  66.            *
  67.            *       Purpose: This function opens a file. Borland's
  68.            *          Turbo C opens files a little different from
  69.            *          the standard UNIX C. Instead of using this
  70.            *          different method in a number of various files,
  71.            *          the method is placed in this one file. If the
  72.            *          programs are moved to another system, all changes
  73.            *          will be located in this one place.
  74.            *
  75.            *       External Calls:
  76.            *          none
  77.            *
  78.            *       Modifications:
  79.            *          18 June 1987 - created
  80.            *
  81.            ****************************************************/
  82.  
  83.  
  84.  
  85. my_open(file_name)
  86.    char file_name[];
  87. {
  88.    int file_descriptor;
  89.  
  90.    file_descriptor = open(file_name, O_RDWR | O_CREAT | O_BINARY, 
  91.                           S_IWRITE);
  92.  
  93.    return(file_descriptor);
  94.  
  95.  
  96. }  /* ends my_open  */
  97.  
  98.        /*****************************************************
  99.        *
  100.        *       file c:\lsu\mrw.c
  101.        *
  102.        *       Functions: This file contains
  103.        *           my_read
  104.        *           my_write
  105.        *
  106.        *       Purpose: These two functions call the Turbo C
  107.        *           functions _read and _write. All software
  108.        *           will use my_read and my_write so that if
  109.        *           the software is ported to another system
  110.        *           that uses read and write changing the
  111.        *           two functions in this file will take care
  112.        *           of the move.
  113.        *
  114.        *       External Call:
  115.        *           read
  116.        *           _write
  117.        *
  118.        *       Modifications:
  119.        *           10 June 1987 - created
  120.        *
  121.        *
  122.        ************************************************************/
  123.  
  124.  
  125. my_read(file_descriptor, buffer, number_of_bytes)
  126.    int  file_descriptor, number_of_bytes;
  127.    char *buffer;
  128. {
  129.    int bytes_read;
  130.    int read();
  131.    bytes_read = read(file_descriptor, buffer, number_of_bytes);
  132.    return(bytes_read);
  133. }
  134.  
  135.  
  136. my_write(file_descriptor, buffer, number_of_bytes)
  137.    int  file_descriptor, number_of_bytes;
  138.    char *buffer;
  139. {
  140.    int bytes_written;
  141.    int write();
  142.    bytes_written = write(file_descriptor, buffer, number_of_bytes);
  143.    return(bytes_written);
  144. }
  145.  
  146.         /******************************************************
  147.         *
  148.         *        file d:\cips\gpcips.c
  149.         *
  150.         *       Functions: This file contains
  151.         *           get_parameters
  152.         *           show_parameters
  153.         *
  154.         *       Purpose - These functions get image parameters.
  155.         *
  156.         *       External Calls:
  157.         *           rstring.c - read_string
  158.         *           intcvrt.c - get_integer
  159.         *
  160.         *       Modifications:
  161.         *           19 February 1987 - These functions were taken out
  162.         *                of the file ip.c.
  163.         *           28 June 1990 - changed to gpcips and the channel
  164.         *                parameter was removed.
  165.         *
  166.         *******************************************************/
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173. get_parameters(il, ie, ll, le)
  174.         int *il, *ie, *le, *ll;
  175. {
  176.         int choice, not_finished;
  177.  
  178.         not_finished = 1;
  179.         while(not_finished){
  180.            show_parameters(il, ie, ll, le);
  181.            printf("\n\nEnter choice to change (enter 0 for no changes) __\b\b");
  182.            get_integer(&choice);
  183.  
  184.            switch (choice){
  185.               case 0:
  186.                  not_finished = 0;
  187.                  break;
  188.  
  189.               case 1:
  190.                  break;
  191.  
  192.               case 2:
  193.                  printf("\nEnter initial line\n___\b\b\b");
  194.                  get_integer(il);
  195.                  break;
  196.  
  197.               case 3:
  198.                  printf("\nEnter initial element\n___\b\b\b");
  199.                  get_integer(ie);
  200.                  break;
  201.  
  202.               case 4:
  203.                  printf("\nEnter last line\n___\b\b\b");
  204.                  get_integer(ll);
  205.                  break;
  206.  
  207.               case 5:
  208.                  printf("\nEnter last element\n___\b\b\b");
  209.                  get_integer(le);
  210.                  break;
  211.  
  212.            }  /* ends switch choice       */
  213.         }     /* ends while not_finished  */
  214. }             /* ends get_parameters      */
  215.  
  216.  
  217. show_parameters(il, ie, ll, le)
  218.         int *il, *ie, *le, *ll;
  219. {
  220.    printf("\n\nThe image parameters are:");
  221.    printf("\n\t2.      il = %4d", *il);
  222.    printf("\n\t3.      ie = %4d", *ie);
  223.    printf("\n\t4.      ll = %4d", *ll);
  224.    printf("\n\t5.      le = %4d", *le);
  225. }  /* ends show_parameters  */
  226.  
  227.        /******************************************************
  228.        *
  229.        *       file d:\cips\intcvrt.c
  230.        *
  231.        *       Functions: This file contains
  232.        *           get_integer
  233.        *           int_convert
  234.        *
  235.        *       Purpose: These functions convert a string of
  236.        *                characters to their number value.
  237.        *
  238.        *       Modifications:
  239.        *            Taken from Jamsa's software package
  240.        *            and altered to fit into the computer
  241.        *            vision programming 22 August 1986.
  242.        *
  243.        *******************************************************/
  244.  
  245.  
  246. #include "d:\cips\numdefs.h"
  247.  
  248.  
  249. get_integer(n)
  250.    int *n;
  251. {
  252.    char string[80];
  253.  
  254.    read_string(string);
  255.    int_convert(string, n);
  256. }
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  int_convert (ascii_val, result)
  263.     char *ascii_val;
  264.     int *result;
  265.   {
  266.     int sign = 1;  /* -1 if negative */
  267.  
  268.     *result = 0;   /* value returned to the calling routine */
  269.  
  270.     /* read passed blanks */
  271.  
  272.     while (is_blank(*ascii_val))
  273.        ascii_val++;              /* get next letter */
  274.  
  275.     /* check for sign */
  276.  
  277.     if (*ascii_val == '-' || *ascii_val == '+')
  278.        sign = (*ascii_val++ == '-') ? -1 : 1;  /* find sign */
  279.  
  280.    /*
  281.     * convert the ASCII representation to the actual
  282.     * decimal value by subtracting '0' from each character.
  283.     *
  284.     * for example, the ASCII '9' is equivalent to 57 in decimal.
  285.     * by subtracting '0' (or 48 in decimal) we get the desired
  286.     * value.
  287.     *
  288.     * if we have already converted '9' to 9 and the next character
  289.     * is '3', we must first multiply 9 by 10 and then convert '3'
  290.     * to decimal and add it to the previous total yielding 93.
  291.     *
  292.     */
  293.  
  294.     while (*ascii_val)
  295.      if (is_digit(*ascii_val))
  296.        *result = *result * 10 + to_decimal(*ascii_val++);
  297.  
  298.      else
  299.        return (IO_ERROR);
  300.  
  301.  
  302.     *result = *result * sign;
  303.  
  304.     return (NO_ERROR);
  305.   }
  306.  
  307.  
  308.  
  309.  
  310.  
  311.          /************************************************
  312.          *
  313.          *         Functions: